
package com.rx.mgt.dao;  

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.DomainInfoExt;
import com.rx.mgt.po.UsersBo;

/** 
 * ClassName:DomainInfoExtDao 
 * Function :
 * Reason   : 
 * Date     :Feb 1, 2017 10:30:27 AM 
 * @author   luolei 
 * @since    JDK 1.6
 */
@Repository
public class DomainInfoExtDao  extends ManagementHibernateDaoBase<DomainInfoExt, Long>{
    @Transactional(readOnly=true)
    public Long getDomainInfoExtCount(UsersBo usersBo){
        String hql= " select count(*) from DomainInfoExt au where 1=1";
        if(StringUtils.isNotBlank(usersBo.getStartDate())){
            hql=hql +" and  unix_timestamp(au.create_time)>unix_timestamp(:startTime)";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getStartDate())){
            query.setParameter("startTime", usersBo.getStartDate());
        }
        return (Long) query.uniqueResult();
    }
    @Transactional(readOnly=true)
    public List<DomainInfoExt>  getDomainInfoExt(UsersBo usersBo){
        String hql= " from DomainInfoExt au where 1=1";
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            hql=hql +" and  au.domain=:domain";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            query.setParameter("domain", usersBo.getDomain());
        }
        return  query.list();
    }

    public DomainInfoExt getDomainInfoExtByDomain(String domain) {
        String hql = " from  DomainInfoExt au where 1=1 and au.domain=:domain";
        Query domain1 = template.getSessionFactory().getCurrentSession().createQuery(hql).setParameter("domain", domain);
        return (DomainInfoExt)domain1.uniqueResult();
    }

    public DomainInfoExt getDomainInfoExtById(String id) {
        String hql = " from  DomainInfoExt au where 1=1 and au.id=:id";
        Query domain1 = template.getSessionFactory().getCurrentSession().createQuery(hql).setParameter("id", id);
        return (DomainInfoExt)domain1.uniqueResult();
    }
}
  